using System;
using System.Runtime.InteropServices;

namespace Control
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class P1240
	{
		public P1240()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		
		/************************************************************************
	   Define Global Value
	************************************************************************/
		public const uint CW = 0;
		public const uint CCW =1;
		public const uint ImmediateStop = 0;
		public const uint SlowStop = 1;
		public const uint RelativeCoordinate = 0;
		public const uint AbsoluteCoordinate = 1;
		public const uint TCurveAcceleration = 0;
		public const uint SCurveAcceleration = 1;
		//***********************************************************************
		// Define Hardware Register Address
		//***********************************************************************
		// These hardware register address can be used in P1240_InpWord and P1240_OutpWord
		public const byte HW_WR0  =  0x00;
		public const byte HW_WR1  =  0x02;
		public const byte HW_WR2  =  0x04;
		public const byte HW_WR3  =  0x06;
		public const byte HW_WR4  =  0x08;
		public const byte HW_WR5  =  0x0A;
		public const byte HW_WR6  =  0x0C;
		public const byte HW_WR7  =  0x0E;
		public const byte HW_RR0  =  0x10;
		public const byte HW_RR1  =  0x12;
		public const byte HW_RR2  =  0x14;
		public const byte HW_RR3  =  0x16;
		public const byte HW_RR4  =  0x18;
		public const byte HW_RR5  =  0x1A;
		public const byte HW_RR6  =  0x1C;
		public const byte HW_RR7  =  0x1E;
		/************************************************************************
		   Define Register ID
		************************************************************************/
		public const ushort Rcnt   =                 0x0100;          /* Real position counter */
		public const ushort Lcnt   =                 0x0101;          /* Logical position counter */
		public const ushort Pcmp   =                 0x0102;          /* P direction compare register */
		public const ushort Ncmp   =                 0x0103;          /* N direction compare register */
		public const ushort Pnum   =                 0x0104;          /* Pulse number */

		public const ushort CurV		=			0x0105;			/* current logical speed */  
		public const ushort CurAC	=				0x0106;			/* current logical acc	*/

		public const ushort SLDN_STOP    =           0x0026;		
		public const ushort IMME_STOP    =           0x0027;

		public const ushort WR3_OUTSL    =           0x0080;

		public const ushort RESET		=			0x8000;
		public const ushort RR0         =            0x0200;          
		public const ushort RR1         =            0x0202;
		public const ushort RR2        =            0x0204;
		public const ushort RR3        =             0x0206;
		public const ushort RR4        =             0x0208;
		public const ushort RR5        =             0x020A;
		public const ushort RR6        =             0x020C;
		public const ushort RR7        =             0x020E;

		public const ushort WR0        =             0x0210;
		public const ushort WR1        =             0x0212;
		public const ushort WR2        =             0x0214;
		public const ushort WR3        =             0x0216;
		public const ushort WR4        =             0x0218;
		public const ushort WR5       =              0x021A;
		public const ushort WR6        =             0x021C;
		public const ushort WR7        =             0x021E;

		public const ushort RG        =              0x0300;
		public const ushort SV       =              0x0301;
		public const ushort DV       =               0x0302;
		public const ushort MDV      =               0x0303;
		public const ushort AC       =               0x0304;
		public const ushort DC       =               0x0305;
		public const ushort AK       =               0x0306;
		public const ushort PLmt      =              0x0307;
		public const ushort NLmt       =             0x0308;
		public const ushort HomeOffset  =            0x0309;
		public const ushort HomeMode    =            0x030A;
		public const ushort HomeType    =            0x030B;
		public const ushort HomeP0_Dir   =           0x030C;
		public const ushort HomeP0_Speed =           0x030D;
		public const ushort HomeP1_Dir   =           0x030E;
		public const ushort HomeP1_Speed =           0x030F;
		public const ushort HomeP2_Dir  =           0x0310;
		public const ushort HomeOffset_Speed=        0x0311;
		//public const ulong RWSN		=		   	0x0312;

		/************************************************************************
		   Define Operation Axis
		************************************************************************/
		public const byte IPO_Axis		=		0x00	;
		public const byte X_Axis      =            0x01;
		public const byte Y_Axis       =           0x02;
		public const byte Z_Axis       =           0x04;
		public const byte U_Axis       =           0x08;
		public const byte  XY_Axis     =            0x03;
		public const byte XZ_Axis      =           0x05;
		public const byte XU_Axis     =            0x09;
		public const byte YZ_Axis      =           0x06;
		public const byte YU_Axis      =           0x0A;
		public const byte ZU_Axis     =            0x0C;
		public const byte XYZ_Axis    =            0x07;
		public const byte XYU_Axis    =            0x0B;
		public const byte XZU_axis    =            0x0D;
		public const byte YZU_Axis    =            0x0E;
		public const byte XYZU_Axis    =           0x0F;

		/************************************************************************
		   Path type for continue moving
		************************************************************************/
		public const ushort IPO_L2       =           0x0030;
		public const ushort IPO_L3       =           0x0031;
		public const ushort IPO_CW       =           0x0032;
		public const ushort IPO_CCW      =           0x0134;

		/************************************************************************
		   Return Code
		************************************************************************/
		public const ushort BoardNumErr           =  0x0001;	
		public const ushort CreateKernelDriverFail=  0x0002;	//internal system error
		public const ushort CallKernelDriverFail  =  0x0003;  //internal system error
		public const ushort RegistryOpenFail      =  0x0004;	//Open registry file fail
		public const ushort RegistryReadFail      =  0x0005;	//Read registry file fail
		public const ushort AxisNumErr            =  0x0006;
		public const ushort UnderRGErr            =  0x0007;
		public const ushort OverRGErr             =  0x0008;
		public const ushort UnderSVErr            =  0x0009;
		public const ushort OverSVErr             =  0x000a;
		public const ushort OverMDVErr            =  0x000b;
		public const ushort UnderDVErr            =  0x000c;
		public const ushort OverDVErr             =  0x000d;
		public const ushort UnderACErr            =  0x000e;
		public const ushort OverACErr             =  0x000f;
		public const ushort UnderAKErr            =  0x0010;
		public const ushort OverAKErr             =  0x0011;
		public const ushort OverPLmtErr           =  0x0012;
		public const ushort OverNLmtErr           =  0x0013;
		public const ushort MaxMoveDistErr        =  0x0014;
		public const ushort AxisDrvBusy           =  0x0015;
		public const ushort RegUnDefine           =  0x0016;
		public const ushort ParaValueErr          =  0x0017;
		public const ushort ParaValueOverRange    =  0x0018;
		public const ushort ParaValueUnderRange   =  0x0019;
		public const ushort AxisHomeBusy          =  0x001a;
		public const ushort AxisExtBusy           =  0x001b;
		public const ushort RegistryWriteFail     =  0x001c;
		public const ushort ParaValueOverErr      =  0x001d;
		public const ushort ParaValueUnderErr     =  0x001e;
		public const ushort OverDCErr             =  0x001f;
		public const ushort UnderDCErr            =  0x0020;
		public const ushort UnderMDVErr           =  0x0021;
		public const ushort RegistryCreateFail    =  0x0022;
		public const ushort CreateThreadErr       =  0x0023;		//internal system fail
		public const ushort HomeSwStop		     =  0x0024;		//P1240HomeStatus
		public const ushort ChangeSpeedErr        =  0x0025;
		public const ushort DOPortAsDriverStatus  =  0x0026;

		public const ushort OpenEventFail        =   0x0030;		//Internal system fail
		public const ushort DeviceCloseErr		=	0x0032;		//Internal system fail

		public const ushort HomeEMGStop          =   0x0040;		//P1240HomeStatus
		public const ushort HomeLMTPStop         =   0x0041;		//P1240HomeStatus
		public const ushort HomeLMTNStop         =   0x0042;		//P1240HomeStatus
		public const ushort HomeALARMStop        =   0x0043;		//P1240HomeStatus

		public const ushort AllocateBufferFail	=			0x0050;
		public const ushort BufferReAllocate		=		0x0051;
		public const ushort FreeBufferFail		=			0x0052;
		public const ushort FirstPointNumberFail	=		0x0053;	
		public const ushort PointNumExceedAllocatedSize	=	0x0054;
		public const ushort BufferNoneAllocate	=			0x0055;
		public const ushort SequenceNumberErr	=			0x0056;	
		public const ushort PathTypeErr			=			0x0057;
		public const ushort PathTypeMixErr		=			 0x0060;
		public const ushort BufferDataNotEnough	=			0x0061;

		public const ushort ChangePositionErr    =    0x0027;    //Change position error


		/************************************************************************
		   External mode
		************************************************************************/
		public const byte JOGDisable          =    0x00;
		public const byte JOGSelfAxis         =    0x01;
		public const byte JOGSelect_XAxis     =    0x02;
		public const byte JOGSelect_YAxis     =    0x03;
		public const byte JOGConnect_XAxis    =    0x04;
		public const byte JOGConnect_YAxis    =    0x05;
		public const byte JOGConnect_ZAxis    =    0x06;
		public const byte JOGConnect_UAxis    =    0x07;
		public const byte HandWheelDisable    =    0x08;
		public const byte HandWheelSelfAxis   =    0x09;
		public const byte HandWheelSelect_XAxis =  0x0a;
		public const byte HandWheelSelect_YAxis =  0x0b;
		public const byte HandWheelFrom_XAxis =    0x0c;
		public const byte HandWheelFrom_YAxis =    0x0d;
		public const byte HandWheelFrom_ZAxis =    0x0e;
		public const byte HandWheelFrom_UAxis =    0x0f;


		// Line Interplation( 2 axes )  
		//		- dwEndPoint_ax1;
		//		- dwEndPoint_ax2;
		//		- wCommand;					; IPO_L2	
		// Line Interplation( 3 axes )  
		//		- dwEndPoint_ax1;
		//		- dwEndPoint_ax2;
		//		- dwEndPoint_ax3;
		//		- wCommand;					; IPO_L3	
		// Arc  Interplation( only 2 axes )  
		//		- dwEndPoint_ax1;			; Arc end point of axis 1
		//		- dwEndPoint_ax2;			; Arc end point of axis 2
		//		- dwCenPoint_ax1;			; Arc center point of axis 1
		//		- dwCenPoint_ax1;			; Arc center point of axis 2	
		//		- wCommand;					; IPO_CW,IPO_CCW		
		public struct MotMoveBuffer
		{
			public long 		dwEndPoint_ax1;		// End position for 1'st axis
            public long         dwEndPoint_ax2;		// End position for 2'nd axis
            public long         dwEndPoint_ax3;		// End position for 3'rd axis
            public long         dwCenPoint_ax1;		// Center position for 1'st axis	
            public long         dwCenPoint_ax2;		// Center position for 2'rd axis
            public long         dwPointNum;			// Serial number for current data

			public ushort			wCommand;			// IPO_CW,IPO_CCW,IPO_L2,IPO_L3 			
			public ushort			TempB;				// For internal using
			public uint			TempA;				// For internal using

		};

        
		public struct MotionDataStruct
		{
			MotMoveBuffer		lpBufIDAddr;	// Buffer address			
			System.Int32 			hBuf;			// Hanlde of Buffer 
			uint				dwAllPointNum;	// How many point of continue move ( get from P1240InitContiBuf)
			bool				bPoint1Flag;	
			uint				dwEndPointNum;
  
		}; 	


		public struct MotSpeedTable
		{

			uint	dwSpeed;	// speed data
			uint	dwComp;		// comparator data
  
		}; 	

		//---------------------------------------------------
		//   Return Code for PCI-1240
		//---------------------------------------------------;
		public const ushort FunctionNotSupport		=		0x0062;
		public const ushort DeviceNotExist           =       0x0063;

		// --------------------------------------------------
		//   Used by PCI-1240 to read write SN
		// --------------------------------------------------
		public const ushort RWSN						=		0x0312;

		// added by yongdong
		public struct VBoard_ID
		{
			byte byBoard_ID;
		};

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotDevOpen", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotDevOpen(byte byBoard_ID);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotDevAvailable", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotDevAvailable(ref uint BoardAvailable);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotDevClose", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotDevClose(byte byBoard_ID);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotAxisParaSet", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotAxisParaSet(byte byBoard_ID,
			byte bySetAxis,
			byte byTS,
			uint dwSV,
			uint dwDV,
			uint dwMDV,
			uint dwAC,
			uint dwAK);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotChgDV", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotChgDV(byte byBoard_ID,
			byte bySetAxis,
			uint dwSetDVValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotChgLineArcDV", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotChgLineArcDV(byte byBoard_ID,
			uint dwSetDVValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotCmove", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotCmove(byte byBoard_ID,
			byte byCMoveAxis,
			byte byAxisDirection);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotPtp", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotPtp(byte byBoard_ID,
			byte byMoveAxis,
			byte byRA,
			ref int lPulseX,
			ref int lPulseY,
			ref int lPulseZ,
			ref int lPulseU);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotLine", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotLine(byte byBoard_ID,
			byte byMoveAxis,
			byte byRA,
			ref int lPulseX,
			ref int lPulseY,
			ref int lPulseZ,
			ref int lPulseU);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotArc", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotArc(byte byBoard_ID,
			byte byMoveAxis,
			byte byRA,
			byte byAxisDirection,
			int lCenter1,
			int lCenter2,
			int lEnd1,
			int lEnd2);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotArcTheta", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotArcTheta(byte byBoard_ID,
			byte byMoveAxis,
			byte byRA,
			int lCenter1,
			int lCenter2,
			double dMoveDeg);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotStop", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotStop(byte byBoard_ID,
			byte byStopAxis,
			byte byStopMode);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotAxisBusy", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotAxisBusy(byte byBoard_ID,
			byte byCheckAxis);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotClrErr", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotClrErr(byte byBoard_ID,
			byte byClearAxis);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotRdReg", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotRdReg(byte byBoard_ID,
			byte byReadAxis,
			ushort wCommandCode,
			ref uint lpReturnValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotWrReg", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotWrReg(byte byBoard_ID,
			byte byWriteAxis,
			ushort wCommandCode,
			uint dwWriteValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotSavePara", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotSavePara(byte byBoard_ID,
			byte bySaveAxis);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotEnableEvent", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotEnableEvent(byte byBoard_ID,
			byte bySettingAxis,
			byte byX_AxisEvent,
			byte byY_AxisEvent,
			byte byZ_AxisEvent,
			byte byU_AxisEvent);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotCheckEvent", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotCheckEvent(byte  byBoard_ID,
			ref ulong lpRetEventStatus,
			uint dwMillisecond);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotRdMutiReg", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotRdMutiReg(byte  byBoard_ID,
			byte  byReadAxis,
			ushort  wCommandCode,
			ref uint lpReturn_XAxisValue,
			ref uint lpReturn_YAxisValue,
		    ref uint lpReturn_ZAxisValue,
			ref uint lpReturn_UAxisValue);

		///wang.long add for function name error 7-27-2006
	
		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotRdMultiReg", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotRdMultiReg(byte  byBoard_ID,
			byte  byReadAxis,
			ushort  wCommandCode,
			ref uint lpReturn_XAxisValue,
			ref uint lpReturn_YAxisValue,
			ref uint lpReturn_ZAxisValue,
			ref uint lpReturn_UAxisValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotWrMutiReg", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotWrMutiReg(byte  byBoard_ID,
			byte  byWriteAxis,
			ushort  wCommandCode,
			uint dwWrite_XAxisValue,
			uint dwWrite_YAxisValue,
			uint dwWrite_ZAxisValue,
			uint dwWrite_UAxisValue);

		///wang.long add for function name error 7-27-2006
		///
		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotWrMultiReg", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotWrMultiReg(byte  byBoard_ID,
			byte  byWriteAxis,
			ushort  wCommandCode,
			uint dwWrite_XAxisValue,
			uint dwWrite_YAxisValue,
			uint dwWrite_ZAxisValue,
			uint dwWrite_UAxisValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotHome", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotHome(byte byBoard_ID,
			byte byHomeAxis);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotHomeStatus", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotHomeStatus(byte byBoard_ID,
			byte byHomeAxis,
			ref uint lpReturnValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotDI", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotDI(byte byBoard_ID,
			byte byReadDIAxis,
			ref byte lpReturnValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotDO", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotDO(byte byBoard_ID,
			byte byWriteDOAxis,
			byte byWriteValue);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotExtMode", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MotExtMode(byte byBoard_ID,
			byte byAssignmentAxis,
			byte byExternalMode,
			int lPulseNum);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MotReset", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern ulong P1240MotReset(byte byBoard_ID);

		[DllImport("Ads1240",
			 EntryPoint = "P1240InitialContiBuf", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240InitialContiBuf(byte byBufID, 
			uint dwAllPointNum);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240FreeContiBuf", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240FreeContiBuf(byte byBufID);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetContiData", 
			 CallingConvention = CallingConvention.StdCall)]
        public static extern int P1240SetContiData(byte byBufID,
			ref MotMoveBuffer		lpPathData,
			uint				dwPointNum);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240StartContiDrive", 
			 CallingConvention = CallingConvention.StdCall)]
        public static extern int P1240StartContiDrive(byte byBoard_ID,
			byte		byMoveAxis,
			byte		byBufID);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetCurContiNum", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetCurContiNum(byte	byBoard_ID,
			ref uint lpReturnValue);

		// Deng Feng add function: change position on fly
		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240ChgPosOnFly", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240ChgPosOnFly(byte	byBoard_ID,
			byte byMoveAxis,
			byte byRA,
			int lPulseX,
			int lPulseY,
			int lPulseZ,
			int lPulseU );

		/********************************************************************
		/* Comparator Function
		/********************************************************************/

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240BuildCompTable", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240BuildCompTable(byte		byBoard_ID,
			byte		byMoveAxis,
			ref ulong	dwTableArray,
			uint	dwAllPointNum	);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240BuildSpeedTable", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240BuildSpeedTable(byte				byBoard_ID,
			byte				byMoveAxis,
			ref MotSpeedTable	SpeedTable,
			uint			dwAllPointNum	);
		/********************************************************************
		/* Directly access the register Functions
    	/********************************************************************/

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetCompPLimit", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetCompPLimit ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			int lWriteValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetCompNLimit", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetCompNLimit ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			int lWriteValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240EnableCompPLimit", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240EnableCompPLimit ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Enable );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240EnableCompNLimit", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240EnableCompNLimit ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Enable );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetPLimitLogic", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetPLimitLogic ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetNLimitLogic", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetNLimitLogic ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetCompareObject", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetCompareObject ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetPulseMode", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetPulseMode ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetPulseLogic", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetPulseLogic ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetPulseDirLogic", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetPulseDirLogic ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetEncoderMultiple", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetEncoderMultiple ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetServoAlarm", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetServoAlarm ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Enable,
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetInPosition", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetInPosition ( 
			byte byBoard_ID, 
			byte bySetAxis, 
			ushort Enable,
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetHomeLogic", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetHomeLogic ( 
			byte byBoard_ID, 
			byte bySetAxis, 								 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetZLogic", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetZLogic ( 
			byte byBoard_ID, 
			byte bySetAxis, 								 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetOutput", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetOutput ( 
			byte byBoard_ID, 
			byte bySetAxis, 								 
			ushort Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetOutputType", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetOutputType ( 
			byte byBoard_ID, 
			byte bySetAxis, 								 
			ushort Enable );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetInputLogic", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetInputLogic ( 
			byte byBoard_ID, 
			byte bySetAxis,
			ushort D4Value,
			ushort D6Value );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetError", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetError (
			byte byBoard_ID, 
			byte byGetAxis,
			ref ushort lpValue	);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetDriverState", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetDriverState (
			byte byBoard_ID, 
			byte byGetAxis,
			ref ushort  lpValue	);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetMotionState", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetMotionState (
			byte byBoard_ID, 
			byte byGetAxis,
			ref ushort lpValue	);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetMotionInput", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetMotionInput (
			byte byBoard_ID, 
			byte byGetAxis,
			ref ushort lpValue	);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetCompareState", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetCompareState (
			byte byBoard_ID, 
			byte byGetAxis,
			ref ushort lpValue	);

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetInput", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetInput (
			byte byBoard_ID, 
			byte byGetAxis,
			ref ushort lpValue );

		// motion functions
		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MoveAbs", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MoveAbs(
			byte byBoard_ID,
			byte byMoveAxis,								 
			int lPulseNumber );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MoveIns", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MoveIns(
			byte byBoard_ID,
			byte byMoveAxis,								 
			int lPulseNumber );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240MoveCircle", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240MoveCircle(
			byte byBoard_ID,
			byte byMoveAxis,
			byte byAxisDirection,								 
			int lCenter1,
			int lCenter2 );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetStartSpeed", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetStartSpeed(
			byte byBoard_ID,
			byte bySetAxis,
			uint lSpeedValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetDrivingSpeed", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetDrivingSpeed(
			byte byBoard_ID,
			byte bySetAxis,
			uint lSpeedValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetAcceleration", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetAcceleration(
			byte byBoard_ID,
			byte bySetAxis,
			uint accel );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetDeceleration", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetDeceleration(
			byte byBoard_ID,
			byte bySetAxis,
			ulong decel,
			int lRetrieve );    

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetJerk", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetJerk(
			byte byBoard_ID,
			byte bySetAxis,
			uint lJerk );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetRange", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetRange(
			byte byBoard_ID,
			byte bySetAxis,
			uint lRange );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetSpeed", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetSpeed (
			byte byBoard_ID, 
			byte byGetAxis,
			ref uint lpValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetAcel", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetAcel (
			byte byBoard_ID, 
			byte byGetAxis,
			ref uint lpValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetPracticalRegister", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetPracticalRegister (
			byte byBoard_ID, 
			byte byGetAxis,
			ref int lpValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240GetTheorecticalRegister", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240GetTheorecticalRegister (
			byte byBoard_ID, 
			byte byGetAxis,
			ref int lpValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetPracticalRegister", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetPracticalRegister(
			byte byBoard_ID,
			byte bySetAxis,
			int lPosition );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240SetTheorecticalRegister", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240SetTheorecticalRegister(
			byte byBoard_ID,
			byte bySetAxis,
			ref int lPosition );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240_OutpWord", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240_OutpWord (
			byte byBoard_ID,
			ushort nPort,
			ushort wWord );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240_InpWord", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240_InpWord(
			byte byBoard_ID,
			ushort nPort,
			ref ushort ptWord );

		// shi.wei added, 2-18-2005.
		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240ReadEEPROM", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240ReadEEPROM(
			byte byBoard_ID, 
			byte byEEPROMAddress, 
			ref ushort pusReadValue );

		[DllImport("Ads1240.dll",
			 EntryPoint = "P1240WriteEEPROM", 
			 CallingConvention = CallingConvention.StdCall)]
		public static extern int P1240WriteEEPROM(
			byte byBoard_ID, 
			byte byEEPROMAddress, 
			ushort usWriteValue );

	}
}
